package com.pansoft.openplanet.util;

import android.widget.TextView;

import com.efounder.utils.ResStringUtil;
import com.pansoft.openplanet.R;
import com.pansoft.openplanet.constant.IPAssetsConstant;

public class ChainParamsUtil {

    /**
     * 判断是否是token账户
     * 用在二维码转账
     *
     * @param tokenAddress
     * @param assetName
     * @return
     */
    public static boolean isTokenAccount(String tokenAddress, String assetName) {
        return (tokenAddress != null &&
                !assetName.equals("ETH") &&
                !assetName.equals("ETE") &&
                !assetName.equals("BTC") &&
                !assetName.equals("EOS") &&
                !assetName.equals("BCH"));
    }

    /**
     * 该链下是否没有token代币资产
     *
     * @param chainId
     * @return true 没有资产
     */
    public static boolean isChainHasNoTokens(int chainId) {
        return (chainId == IPAssetsConstant.CHAIN_ID_BTC ||
                chainId == IPAssetsConstant.CHAIN_ID_BCH ||
                chainId == EosNetParamUtil.getEosChainId() ||
                chainId == IPAssetsConstant.CHAIN_ID_ETE);
    }

    /**
     * 根据chainId获取ChainUnit
     *
     * @param ipaChainId 链的id
     * @return
     */
    public static String getAssetUnitByChainId(int ipaChainId) {
        return getAssetUnitByChainId(ipaChainId, null, "");
    }

    /**
     * 根据chainId获取ChainUnit
     *
     * @param ipaChainId 链的id
     * @param tvExpense
     * @param gas
     * @return
     */
    public static String getAssetUnitByChainId(int ipaChainId, TextView tvExpense, String gas) {
        String assetUnit = "";
        if (ipaChainId == IPAssetsConstant.CHAIN_ID_ETH) {
            assetUnit = "ETH";
        } else if (ipaChainId == IPAssetsConstant.CHAIN_ID_ETE) {
            assetUnit = "ETE";
            if (tvExpense != null) {
                tvExpense.setText(gas + " ETE");
            }
        } else if (ipaChainId == IPAssetsConstant.CHAIN_ID_BTC) {
            assetUnit = "BTC";
            if (tvExpense != null) {
                tvExpense.setText(gas + " sat/byte");
            }

        } else if (ipaChainId == EosNetParamUtil.getEosChainId()) {
            assetUnit = "EOS";
            if (tvExpense != null) {
                tvExpense.setText(gas + " eos");
            }
        } else if (ipaChainId == IPAssetsConstant.CHAIN_ID_BCH) {
            assetUnit = "BCH";
        } else if (ipaChainId == IPAssetsConstant.CHAIN_ID_TURBOCHAIN) {
            assetUnit = "PWR";
        }
        return assetUnit;
    }


    /**
     * 获取交易手续费的单位
     *
     * @param chainId
     * @return
     */
    public  static String getGasUnitByChainId(int chainId) {
        String gasUnit = "";
        if (chainId == IPAssetsConstant.CHAIN_ID_BTC) {
            gasUnit = "sat/byte";
        } else if (chainId == IPAssetsConstant.CHAIN_ID_ETH) {
            gasUnit = "gwei";
        } else if (chainId == EosNetParamUtil.getEosChainId()) {
            gasUnit = "eos";
        } else {
            gasUnit = "gwei";
        }
        return gasUnit;
    }

    public static void setTransactionResultHint(int mode, String moneyUnit, String
            gasUnit, String copyAddressToast) {
        if (mode == IPAssetsConstant.CHAIN_ID_BTC) {
            moneyUnit = "BTC";
            copyAddressToast = "BTC" + ResStringUtil.getString(R.string.open_planet_asset_mine_pwr_address_copied);
            gasUnit = "btc";
        } else if (mode == IPAssetsConstant.CHAIN_ID_ETH) {
            moneyUnit = "ETH";
            gasUnit = "ether";
            copyAddressToast = "ETH" + ResStringUtil.getString(R.string.open_planet_asset_mine_pwr_address_copied);
        } else if (mode == EosNetParamUtil.getEosChainId()) {
            moneyUnit = "eos";
            copyAddressToast = "EOS" + ResStringUtil.getString(R.string.open_planet_asset_mine_pwr_address_copied);
        } else if (mode == IPAssetsConstant.CHAIN_ID_TURBOCHAIN) {
            moneyUnit = "PWR";
            copyAddressToast = ResStringUtil.getString(R.string.open_planet_asset_mine_pwr_base_id_copied);
            gasUnit = "PWR";
        } else if (mode == IPAssetsConstant.CHAIN_ID_ETE) {
            moneyUnit = "ETE";
            copyAddressToast = "ETE" + ResStringUtil.getString(R.string.open_planet_asset_mine_pwr_address_copied);
        }
    }
}
